import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import piniaPersistConfig from "@/config/piniaPersist";
import { getUserInfo } from "@/api/modules/account";

export const useUserStore = defineStore({
  id: "geeker-user",
  state: (): UserState => ({
    token: "",
    userInfo: { name: "未知用户", avatar: "", phone: "", roleName: "", prefix: "", belong: "" }
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    // Set setUserInfo
    async setUserInfo() {
      const { data } = await getUserInfo();
      this.userInfo = data as any;
    }
  },
  persist: piniaPersistConfig("geeker-user")
});
